from odoo import fields, models


class PlanRemarkWizard(models.Model):
    _name = 's.plan.remark.wizard'
    _description = 'Plan Remark Wizard'

    sale_order_line_id = fields.Many2one('sale.order.line', string='Sale Line')
    note = fields.Text(string='Remark')

    def default_get(self, fields_list):
        result = super().default_get(fields_list)
        active_model = self._context.get('active_model', '')
        if active_model == 'sale.order.line':
            sale_order_line = self._context.get('active_id')
            sale_order_line = self.env[active_model].browse(sale_order_line)
            result.update({
                'sale_order_line_id': sale_order_line.id,
                'note': sale_order_line.s_plan_note
            })
        return result

    def action_confirm(self):
        self.sudo().sale_order_line_id.s_plan_note = self.note
